package com.example.springboot.err;


import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice(basePackages = "com.example.springboot.controller")
public class errData {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Map errData(RuntimeException runtimeException){
        Map<Object, Object> errData = new HashMap<>();
        errData.put("err","异常");
        return errData;
    }

//    @ExceptionHandler({ RuntimeException.class })
//    @ResponseStatus(HttpStatus.OK)
//    public ModelAndView processException(Exception exception) {
//        ModelAndView m = new ModelAndView();
//        m.addObject("roncooException", exception.getMessage());
//        m.setViewName("errPage");
//        return m;
//    }
}
